<template>
  <div>
    <search-list
      ref="authorList"
      :api-url="$url.IdentificationAuthorList"
      :option="searchOpt"
      :itemPerRow="5"
    >
      <el-table-column prop="uid" label="认证用户ID"></el-table-column>
      <el-table-column prop="nickname" label="认证用户"></el-table-column>
      <el-table-column prop="profession" label="职业"></el-table-column>
      <el-table-column prop="showName" label="认证说明"></el-table-column>
      <el-table-column prop="year" label="入行年份"></el-table-column>
      <el-table-column prop="address" label="所在地区">
        <template slot-scope="scope">
          <span>
            {{
              scope.row.province == scope.row.city
                ? scope.row.province
                : scope.row.province + scope.row.city
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="applyAt" label="时间" min-width="180">
        <template slot-scope="scope">
          <p>更新：{{ scope.row.updatedAt }}</p>
          <p>申请：{{ scope.row.applyAt }}</p>
          <p>创建：{{ scope.row.createdAt }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="checked" label="审核状态">
        <template slot-scope="scope">
          <span>
            {{ $selectFormat['checkedSl'](scope.row.checked).label }}
          </span>
        </template>
      </el-table-column>
      <el-table-column prop="realIdentified" label="实名认证情况">
        <template slot-scope="scope">
          <span>
            {{ $selectFormat['realNamecheckedSl'](scope.row.realIdentified).label }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="280px">
        <template slot-scope="scope">
          <el-button type="text" @click="detail(scope.row)">详情</el-button>
          <el-button type="text" @click="pass(scope.row)">审核通过</el-button>
          <el-button type="text" @click="noPass(scope.row)">审核不通过</el-button>
        </template>
      </el-table-column>
    </search-list>
    <el-dialog width="500px" title="填写审核不通过原因" :visible.sync="dialogShow">
      <el-form>
        <el-form-item label="原因">
          <el-input v-model.trim="reason"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button icon="el-icon-close" @click="dialogClose">关 闭</el-button>
        <el-button type="success" @click="saveReason" icon="el-icon-check">保 存</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        dialogShow: false,
        reason: '',
        selectedData: [],
        uid: '',
        searchOpt: [
          {
            type: this.SEARCH_COMP_ENUM.SEARCH_INPUT,
            name: 'uuid',
            label: '用户ID',
          },
          {
            type: 'checkedSl',
            name: 'checked',
            label: '审核状态',
          },
          {
            type: 'realNamecheckedSl',
            name: 'realIdentified',
            label: '实名认证情况',
          },
        ],
      };
    },
    created() {},
    computed: {},
    methods: {
      detail(row) {
        const { uid } = row;
        this.$tabs.open({ name: 'IdentificateAuthorDetail', params: { uid } });
      },
      pass(row) {
        const { uid } = row;
        this.$service
          .IdentificationPass({
            kind: 'author',
            uuid: uid,
          })
          .then((res) => {
            this.$message.success('审核通过');
            this.$refs['authorList'].getList();
          })
          .catch((res) => {
            this.$message.error(res.message);
          });
      },
      noPass(row) {
        this.dialogShow = true;
        this.uid = row.uid;
      },
      dialogClose() {
        this.dialogShow = false;
      },
      saveReason() {
        if (this.reason == '') {
          this.$message.warning('请输入不通过原因');
          return;
        } else {
          this.$service
            .IdentificationRefuse({
              kind: 'author',
              uuid: this.uid,
              remark: this.reason,
            })
            .then((res) => {
              this.dialogShow = false;
              this.$message.success('操作成功');
              this.$refs['authorList'].getList();
              this.selectedData = [];
            });
        }
      },
    },
  };
</script>
<style lang="less" scoped></style>
